<template>
	<view class="home">
		<!-- 导航部分 -->
		<u-tabs-swiper ref="tabs" name="cate_name" :list="list" :is-scroll="true" :current="current" @change="change"
		 active-color="#000" font-size="34" ></u-tabs-swiper>

		<view class="" v-if="current === 0">
			<view class="info" v-for="item in TaskInfo" :key="item.id" v-if="item.publisher_number == User_number && item.whether_finished_order == 0"
			 :style="item.STY_background">
				<view class="flex-row">
					<text class="name">名称：{{item.name}}</text>
					<text class="">取件码：{{item.get_code}}</text>
				</view>
				<view class="flex-row">
					<text class="">手机号码：{{item.telephone}}</text>
					<text class="flex-1"></text>
					<text class="">快递大小：{{item.size}}</text>
				</view>
				<view class="flex-row">
					<text class="">快递类型：{{item.type}}</text>
					<text class="flex-1"></text>
					
				</view>
				<view class="">送货地址：{{item.give_item}}</view>
				<view class="flex-row">取件地址：{{item.take_item}}</view>
				<view class="flex-row">
					备注：{{item.Notes}}
				</view>
				<view class="split-line"></view>
				<view class="btns">
					<button :type="item.type_color" class="transit"  @click="" disabled>运输中</button>
					<button type="default" style="background: #FCBD71; color: #FFFFFF;" @click="if_Finish(item.id)">确定收货</button>
					<button type="warn" style="" @click="if_remove(item.id)">删除</button>
				</view>

			</view>

			<view class="Tips" v-show="SHOW === 1">
				你还未发布任何订单哦~
			</view>
		</view>

		<view class="" v-if="current === 1">
			<view class="info" style="background-color: rgba(216,30,6,0.1);" v-for="item in BoxInfo" :key="item.id" v-if="item.number == User_number && item.whether_finished == 0 && item.type == 1"   :style="item.STY_background">
				<view class="flex-row">
					<text class="name">昵称: {{item.name}}</text>
					<text class="flex-1"></text>
					<text class="">手机号码: {{item.telephone}}</text>
				</view>
				<view class="flex-row">金额: {{item.money}}元</view>
				<view class="flex-row">买饭地址: {{item.intro}}</view>
				<view class="flex-row">送饭地址: {{item.give_Address}}</view>
				<view class="flex-row">时间: {{item.time}}</view>
				<view class="split-line"></view>
				<view class="btns">
					<button :type="item.type_color" class="transit"  @click="" disabled>运输中</button>
					<button type="default" style="background: #FCBD71; color: #FFFFFF;" @click="if_Finish(item.id)">确定收货</button>
					<button type="warn" style="" @click="if_remove(item.id)">删除</button>
				</view>
				
			</view>

			<view class="Tips" v-show="SHOW_box === 1">
				你还未发布任何订单哦~
			</view>
		</view>

		<view class="" v-if="current === 2">
			<view class="info" style="background-color: rgba(26,250,41,0.2);" v-for="item in BoxInfo" :key="item.id" v-if="item.number == User_number && item.whether_finished == 0 && item.type == 2">
				<view class="flex-row">
					<text class="name">昵称: {{item.name}}</text>
					<text class="">手机号码: {{item.telephone}}</text>
				</view>
				<view class="flex-row">金额: {{item.money}}元</view>
				<view class="flex-row">时间: {{item.time}}</view>
				<view class="flex-row">买物地址: {{item.intro}}</view>
				<view class="flex-row">买物地址: {{item.give_Address}}</view>
				<view class="split-line"></view>
		
				<view class="btns">
					<button :type="item.type_color" class="transit" style="" @click="" disabled>运输中</button>
					<button type="default" style="background: #FCBD71; color: #FFFFFF;" @click="if_Finish(item.id)">确定收货</button>
					<button type="warn" style="" @click="if_remove(item.id)">删除</button>
				</view>
				
			</view>

			<view class="Tips" v-show="SHOW_food === 1">
				你还未发布任何订单哦~
			</view>
		</view>

		<view class="" v-if="current === 3">
			<view class="info" style="background-color: rgba(19,24,122,0.3);" v-for="item in PrintInfo" :key="item.id" v-if="item.number == User_number && item.whether_finished == 0">
				<view class="flex-row">
					<text class="name">昵称: {{item.name}}</text>
					<text class="flex-1"></text>
					<text class="flex-row">手机号码: {{item.telephone_number}}</text>
				</view>
				<view class="flex-row">打印地点: {{item.get_Address}}</view>
				<view class="flex-row">金额: {{item.money}}元</view>
				<view class="flex-row">送货地址: {{item.give_Address}}</view>
				<view class="flex-row">备注: {{item.Notes}}</view>
				<view class="split-line"></view>
				<view class="btns">
					<button :type="item.type_color" class="transit" style="" @click="" disabled>运输中</button>
					<button type="default" style=" background: #FCBD71; color: #FFFFFF;" @click="if_Finish(item.id)">确定收货</button>
					<button type="warn" style="" @click="if_remove(item.id)">删除</button>
				</view>
				
			</view>

			<view class="Tips" v-show="SHOW_print === 1">
				你还未发布任何订单哦~
			</view>
		</view>

		<view class="add">
			<image :src="url" mode="" @click="add_Task"></image>
		</view>

		<view>
			<u-popup v-model="show_mask" mode="bottom" border-radius="14" length="50%" closeable="true">
				<view style="margin-top: 40px;">
					<view style="margin: 0 auto;width: 85px;font-size: 20px;">用户评价</view>
					<textarea @blur="" placeholder="请输入评价内容" style="border-radius: 14px;margin: 0 auto;padding: 5px;" v-model="Evaluation"/>
					<button type="primary" style="width: 30%;font-size: 18px;margin-top: 5px;" @click="evalu">输入完成</button>
				</view>
			</u-popup>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				TaskInfo: [],
				BoxInfo: [],
				PrintInfo: [],
				User_number: '',
				// 205,92,92,0.8
				// 0,128,0,0.7
				background_color: [
					"background: rgba(0,144,255,0.3);",
					"background: rgba(0,144,255,0.3);",
					"background: rgba(0,144,255,0.3);"
				],
				background_color1:[
					"background: rgba(26,250,41,0.3);",
					"background: rgba(0,1,255,0.5);",
					"background: rgba(0,1,255,0.3);"
				],
				SHOW: 1,
				SHOW_box: 1,
				SHOW_food: 1,
				SHOW_print: 1,
				list: [{
					cate_name: '快递发布'
				}, {
					cate_name: '盒饭发布'
				}, {
					cate_name: '零食发布'
				}, {
					cate_name: '打印发布'
				}],
				current: 0,
				url: '../../static/temp/add_Task.png',
				show_mask:false,
				Evaluation:'',
				index_Task:0
			}
		},
		methods: {
			async getTaskInfo() {
				const res = await this.$myRequest({
					url: 'getTaskInfo'
				})
				if (res.data.code == 0) {
					this.TaskInfo = res.data.message;
					console.log(this.TaskInfo, '819819819819819')
					for (let i = 0; i < this.TaskInfo.length; i++) {
						if (this.TaskInfo[i].publisher_number == this.User_number) {
							this.SHOW = 0;
							break;
						}
					}
				}
				let j = 0;
				for (let i = 0; i < this.TaskInfo.length; i++) {
					if (this.TaskInfo[i].publisher_number == this.User_number && this.TaskInfo[i].whether_finished_order == 0) {
						this.TaskInfo[i]['STY_background'] = this.background_color[j];
						++j;
					}
					if (j == 3) {
						j = 0;
					}
				}

				for (let z = 0; z < this.TaskInfo.length; z++) {
					if (this.TaskInfo[z].select_paoshou == "") {
						this.TaskInfo[z]['type_color'] = 'default';
					} else {
						this.TaskInfo[z]['type_color'] = 'primary';
					}
				}
			},
			async GetBoxMessage() {
				const res = await this.$myRequest({
					url: 'GetTaskMessage'
				})
				if (res.data.code == 0) {
					this.BoxInfo = res.data.message;
					console.log(this.BoxInfo,'this is BoxInfo!!!!');
					for (let i = 0; i < this.BoxInfo.length; i++) {
						if (this.BoxInfo[i].number == this.User_number && this.BoxInfo[i].whether_finished == 0 && this.BoxInfo[i].type ==
							1) {
							this.SHOW_box = false;
						}
						if (this.BoxInfo[i].number == this.User_number && this.BoxInfo[i].whether_finished == 0 && this.BoxInfo[i].type ==
							2) {
							this.SHOW_food = false;
						}
					}
					
					let j = 0;
					for (let i = 0; i < this.BoxInfo.length; i++) {
						// console.log(this.BoxInfo[i].select_paoshou ,this.User_number, this.BoxInfo[i].whether_finished );
						if (this.BoxInfo[i].select_paoshou == this.User_number && this.BoxInfo[i].whether_finished == 0) {
							this.BoxInfo[i]['STY_background'] = this.background_color1[j];
							console.log(this.BoxInfo[i]['STY_background']);
							++j;
						}
						if (j >= this.BoxInfo.length) {
							j = 0;
						}
					}
					
					
				}
			},
			async GetPrintMessage() {
				const res = await this.$myRequest({
					url: 'GetPrintMessage'
				})
				if (res.data.code == 0) {
					this.PrintInfo = res.data.message;
					for (let i = 0; i < this.PrintInfo.length; i++) {
						if (this.PrintInfo[i].number == this.User_number && this.PrintInfo[i].whether_finished == 0) {
							this.SHOW_print = false;
						}
					}
				}
			},
			add_Task() {
				if (this.current == 0) {
					uni.navigateTo({
						url: '../../pagesA/add_task/add_task?number=' + this.User_number
					})
				} else if (this.current == 1 || this.current == 2) {
					uni.navigateTo({
						url: '../../pagesA/add_boxTask/add_boxTask?number=' + this.User_number
					})
				} else {
					uni.navigateTo({
						url: '../../pagesA/Add_PrintTask/Add_PrintTask?number=' + this.User_number
					})
				}
			},
			if_remove(index) {
				uni.showModal({
					title: '温馨提示',
					content: '您确实要删除该任务嘛？',
					success: (res) => {
						if (res.confirm) {
							this.remove(index);
						}
					}
				})
			},
			async remove(index) {
				const Res = await uni.request({
					url: 'http://3888n9t950.wicp.vip/remove_Task?id=' + index
				})
				
				// 改成全局接口请求的封装
				// let url = 'http://192.168.137.1:8080/revise_ifRunner';
				// const res = await this.$myRequest({
				// 	url: `/remove_Task?id=' + index`
				// })
				
				if (Res[1].data.code == 1) {
					uni.showToast({
						title: '订单有人接啦',
						mask: true,
						duration: 1500
					})
				} else {
					uni.showToast({
						title: '删除成功',
						mask: true,
						duration: 800
					})
				}
			},
			change(index) {
				this.current = index;
				if (this.current == 0) {
					this.url = '../../static/temp/add_Task.png'
				} else if (this.current == 1) {
					this.url = '../../static/temp/add_Task(1).png'
				} else if (this.current == 2) {
					this.url = '../../static/temp/add_Task(2).png'
				} else {
					this.url = '../../static/temp/add_Task(3).png'
				}
			},
			if_Finish(index) {
				if(this.TaskInfo[index].select_paoshou == ''){
					uni.showToast({
						title:'还未有人接手哦~',
						mask:true,
						duration:1500
					})
					return;
				}
				uni.showModal({
					title: '温馨提示',
					content: '确定收货？',
					success: (res) => {
						if (res.confirm) {
							this.Finish(index);
						}
					}
				})
			},
			async Finish(index) {
				const res = await this.$myRequest({
					url: 'Finish_Task_order?id=' + index
				})
				// console.log(res);
				if (res.data.code == 0) {
					uni.showToast({
						title: '收货成功!',
						mask: true,
						duration: 1500,
						success: () => {
							this.getTaskInfo();
							this.show_mask = true;
							this.index_Task = index;
						}
					})
				}
			},
			async evalu(){
				if(this.Evaluation == ''){
					uni.showToast({
						title:'评价不能为空哦！',
						mask:true,
						duration:1500
					})
					return;
				}
				console.log(this.Evaluation)
				let temp,name;
				for(let i=0;i<this.TaskInfo.length;i++){
					if(this.TaskInfo[i].id == this.index_Task){
						temp = this.TaskInfo[i].select_paoshou;
						name = this.TaskInfo[i].name;
					}
				}
				const res = await this.$myRequest({
					url:`Get_exp_eva?User=${this.User_number}&paoshou=${temp}&Eval=${this.Evaluation}&name=${name}`
				})
				console.log(res);
				if(res.data.code == 0){
					uni.showToast({
						title:'评价成功！',
						mask:true,
						duration:1500,
						success:()=>{
							this.show_mask = false;
						}
					})
				}
			}
		},
		onLoad(options) {
			// console.log(options);
			this.User_number = options.number;
			// this.User_number = 'B20190306118';
			this.getTaskInfo();
			this.GetBoxMessage();
			this.GetPrintMessage();
		},
		onPullDownRefresh() {
			this.getTaskInfo();
			this.GetBoxMessage();
			this.GetPrintMessage();
			setInterval(() => {
				uni.stopPullDownRefresh();
			}, 2000)
		}
	}
</script>

<style lang="scss">
	.home {
		position: relative;
		width: 100%;
		.flex-row{
			display: flex;
			justify-content: space-between;
			flex-direction: row;
			// border-bottom:2rpx solid #333 ;
		}
		.flex-1{
			flex: 1;
		}
		.Info {
			width: 100%;
			border: 1px solid #C0C0C0;
			padding: 50rpx 30rpx;
			font-size: 35rpx;
			// border-radius: 60rpx;
			color: #FFFFFF;

			view {
				width: 750rpx;
				height: 70rpx;
				line-height: 70rpx;
				text-align: center;
			}
		}

		.info {
			width: 92%;
			padding: 50rpx 0;
			font-size: 35rpx;
			margin: 20rpx auto 0;
			display: flex;
			flex-direction: column;
			border-bottom-left-radius: 20rpx;
			border-bottom-right-radius: 20rpx;
			color: #000000;
			.split-line{
				width: 100%;
				height: 2rpx;
				background-color: #C0C0C0 ;
				margin:30rpx 0 40rpx;
			}
			.btns{
				display: flex;
				justify-content: space-between;
				button{
					margin: 0;
					font-size: 28rpx;
					border-radius: 35rpx;
					padding: 0 58rpx;
					height: 70rpx;
					line-height: 70rpx;
					&.transit{
						color: #787878;
						background-color: #d9d9d9;
					}
				}
				
				button::after{
					border: none;
				}
			}
			view {
				padding: 0 30rpx;
				height: 80rpx;
				line-height: 80rpx;
				font-size: 30rpx;
				text-align: left;
			}
		}

		.add {
			width: 120rpx;
			height: 120rpx;
			position: fixed;
			bottom: 80rpx;
			right: 24rpx;

			image {
				width: 120rpx;
				height: 120rpx;
			}
		}

		.Tips {
			width: 100%;
			height: 300px;
			line-height: 300px;
			font-size: 50rpx;
			color: #C8C7CC;
			text-align: center;
		}

		.bottom {
			width: 100%;
			border: 1px solid #DCDFE6;
			height: 40px;
			font-size: 18px;
			line-height: 40px;
			text-align: center;
			color: #C8C7CC;
		}
	}
</style>
